#include <memory>
#include <session.h>
#include <connection.h>
#include <iostream>

using namespace std;

class Client:public Session {


	public:
		Client(int id);
		void doSend(char type, uint32_t bounds, std::vector<char> &body) override;
		void doWork(const Protocal &data) override;
};

Client::Client(int id):Session(id)
{

}

void Client::doSend(char type, uint32_t bounds, std::vector<char> &body)
{
	Session::doSend(type, bounds, body);
}

void Client::doWork(const Protocal &data)
{
	cout << data.head.counter << endl;
	cout << data.head.id << endl;
	cout << data.head.len << endl;
}

class Server{
	public:
		Server();
	private:
		Dispatcher dp;
		std::vector<std::shared_ptr<Client>> mClients;
};

Server::Server():dp(nullptr)
{
	dp.Create_Socket();
	dp.Bind("0.0.0.0", 6665);
	auto cb = ([this](Socket s){
			static int i = 0;
			std::shared_ptr<Client> clt(new Client(i));
			mClients.push_back(clt);
			clt->start(s);
			std::cout << "new connection accept" << std::endl;
			
			});

	dp.Listen(cb);
}

int main(int argc, char* argv[]) {
	Server s;
	
	Dispatcher::Loop();
	return 0;
}
